<?php



class important extends connector {

	function important() {
		$this->softbase(true);
	}

	function onbatcreate() {
		$this->powercheck(205, 240);
		parent::start_template();
		$tab = $this->fun->accept('tab', 'R');
		$tab = empty($tab) ? 'true' : $tab;

		$file_htmldir = $this->CON['file_htmldir'];
		$lng = $this->fun->accept('lng', 'R');
		$lng = empty($lng) ? ($this->CON['is_alonelng'] && !empty($this->CON['home_lng'])) ? $this->CON['home_lng'] : $this->CON['default_lng'] : $lng;
		$time = time();
		$is_html = $this->CON['is_html'];
		$this->ectemplates->assign('is_html', $is_html);

		$lnglist = $this->get_lng_array($lng, 1);
		$this->ectemplates->assign('lnglist', $lnglist['list']);
		$this->ectemplates->assign('tab', $tab);
		$this->ectemplates->assign('time', $this->fun->formatdate($time, 2));
		$this->ectemplates->assign('htmldir', $file_htmldir);
		$this->ectemplates->assign('is_alonelng', $this->CON['is_alonelng']);
		$this->ectemplates->assign('home_lng', $lng);
		$this->ectemplates->assign('lng', $lng);
		$this->ectemplates->display('creat/creat_bat');
	}

	function oncreatebatwindow() {
		$this->powercheck(205, 240);
		parent::start_template();
		$read['lng'] = $this->fun->accept('lng', 'R');
		$lng = ($read['lng'] == 'big5') ? $this->CON['is_lancode'] : $read['lng'];
		$read['creattype'] = $this->fun->accept('creattype', 'R');
		$read['time'] = $this->fun->accept('time', 'R');

		$modelarray = $this->get_model(0, $lng, 1, 1);
		$modelist = $modelarray['list'];
		$num = $modelarray['num'];
		$midlist = null;
		if ($num > 0) {
			$numcount = $num - 1;
			foreach ($modelist as $key => $value) {
				if ($key == $numcount) {
					$midlist.=$value['mid'];
				} else {
					$midlist.=$value['mid'] . ',';
				}
			}
		}
		$is_html = $this->CON['is_html'];
		$this->ectemplates->assign('is_html', $is_html);
		$this->ectemplates->assign('modelarray', $modelarray['list']);
		$this->ectemplates->assign('midlist', $midlist);
		$this->ectemplates->assign('read', $read);
		$this->ectemplates->display('creat/create_bat_window');
	}

	function oncreateindex() {
		$this->powercheck(205, 206);
		parent::start_template();
		$tab = $this->fun->accept('tab', 'R');
		$tab = empty($tab) ? 'true' : $tab;

		$file_htmldir = $this->CON['file_htmldir'];

		$file_fileex = $this->CON['file_fileex'];

		$entrance_file = $this->CON['entrance_file'];
		$lng = $this->fun->accept('lng', 'R');
		$lng = empty($lng) ? ($this->CON['is_alonelng'] && !empty($this->CON['home_lng'])) ? $this->CON['home_lng'] : $this->CON['default_lng'] : $lng;

		$lnglist = $this->get_lng_array($lng, 1);
		$this->ectemplates->assign('lnglist', $lnglist['list']);
		$this->ectemplates->assign('tab', $tab);
		$this->ectemplates->assign('is_alonelng', $this->CON['is_alonelng']);
		$this->ectemplates->assign('home_lng', $lng);
		$this->ectemplates->assign('htmldir', $file_htmldir);
		$this->ectemplates->assign('fileex', $file_fileex);
		$this->ectemplates->assign('entrance', $entrance_file);
		$this->ectemplates->assign('lng', $lng);
		$this->ectemplates->display('creat/creat_index');
	}

	function oncreateindexwindow() {
		$this->powercheck(205, 206);
		parent::start_template();
		$read['lng'] = $this->fun->accept('lng', 'R');
		$read['time'] = time();
		$is_html = $this->CON['is_html'];
		$this->ectemplates->assign('is_html', $is_html);
		$this->ectemplates->assign('read', $read);
		$this->ectemplates->display('creat/create_index_window');
	}

	function oncreatetype() {
		$this->powercheck(205, 207);
		parent::start_template();
		$tab = $this->fun->accept('tab', 'R');
		$tab = empty($tab) ? 'true' : $tab;

		$mid = $this->fun->accept('mid', 'R');
		$mid = empty($mid) ? 0 : $mid;

		$lng = $this->fun->accept('lng', 'R');
		$lng = empty($lng) ? ($this->CON['is_alonelng'] && !empty($this->CON['home_lng'])) ? $this->CON['home_lng'] : $this->CON['default_lng'] : $lng;

		$lnglist = $this->get_lng_array($lng, 1);
		$this->ectemplates->assign('lnglist', $lnglist['list']);

		$modelarray = $this->get_model(0, $lng, 1, 1);
		$this->ectemplates->assign('modelarray', $modelarray['list']);
		$this->ectemplates->assign('is_alonelng', $this->CON['is_alonelng']);
		$this->ectemplates->assign('home_lng', $lng);
		$this->ectemplates->assign('tab', $tab);
		$this->ectemplates->display('creat/creat_type');
	}

	function oncreatewindow() {
		$this->powercheck(205, 207);
		parent::start_template();
		$read['lng'] = $this->fun->accept('lng', 'R');
		$read['mid'] = $this->fun->accept('mid', 'R');
		$read['tid'] = $this->fun->accept('tid', 'R');
		$read['creattype'] = $this->fun->accept('creattype', 'R');
		$read['pnumber'] = $this->fun->accept('pnumber', 'R');
		$read['class'] = $this->fun->accept('class', 'R');
		$read['time'] = time();
		$is_html = $this->CON['is_html'];
		$this->ectemplates->assign('is_html', $is_html);
		$this->ectemplates->assign('read', $read);
		$this->ectemplates->display('creat/create_type_window');
	}

	function onstatype() {
		$lng = $this->fun->accept('lng', 'R');
		$lng = ($lng == 'big5') ? $this->CON['is_lancode'] : $lng;
		$mid = $this->fun->accept('mid', 'R');
		$tid = $this->fun->accept('tid', 'R');
		$creattype = $this->fun->accept('creattype', 'R');
		$pnumber = $this->fun->accept('pnumber', 'R');
		$class = $this->fun->accept('class', 'R');
		if (empty($lng) || empty($mid)) {
			exit('false');
		}
		$lanpackfile = admin_ROOT . 'datacache/' . $lng . '_pack.php';
		if (!is_file($lanpackfile)) {

			$this->creat_lanpack($lng, true);
		}

		if ($creattype == 1) {
			$typelist = $this->get_typeid($tid, '', 0, $mid, 0, $lng, 0, 1, 'text');
			if (!empty($typelist)) {
				$typearray = explode(',', $typelist);

				$num = count($typearray);
			} else {
				$num = 0;
			}
		} else {
			$typelist = $tid;
			$num = 1;
		}
		$var = '{"num":"' . $num . '","typelist":"' . $typelist . '","mid":"' . $mid . '","lng":"' . $lng . '"}';
		exit($var);
	}

	function oncreatesubject() {
		$this->powercheck(205, 210);
		parent::start_template();
		$tab = $this->fun->accept('tab', 'R');
		$tab = empty($tab) ? 'true' : $tab;

		$mid = $this->fun->accept('mid', 'R');
		$mid = empty($mid) ? 0 : $mid;

		$lng = $this->fun->accept('lng', 'R');
		$lng = empty($lng) ? ($this->CON['is_alonelng'] && !empty($this->CON['home_lng'])) ? $this->CON['home_lng'] : $this->CON['default_lng'] : $lng;

		$lnglist = $this->get_lng_array($lng, 1);
		$this->ectemplates->assign('lnglist', $lnglist['list']);

		$modelarray = $this->get_model(0, $lng, 1, 1);
		$this->ectemplates->assign('modelarray', $modelarray['list']);
		$this->ectemplates->assign('tab', $tab);
		$this->ectemplates->assign('is_alonelng', $this->CON['is_alonelng']);
		$this->ectemplates->assign('home_lng', $lng);
		$this->ectemplates->display('creat/creat_subject');
	}

	function oncreatesubwindow() {
		$this->powercheck(205, 210);
		parent::start_template();
		$read['lng'] = $this->fun->accept('lng', 'R');
		$read['mid'] = $this->fun->accept('mid', 'R');
		$read['sid'] = $this->fun->accept('sid', 'R');
		$read['time'] = time();
		$is_html = $this->CON['is_html'];
		$this->ectemplates->assign('is_html', $is_html);
		$this->ectemplates->assign('read', $read);
		$this->ectemplates->display('creat/create_subject_window');
	}

	function onstasub() {
		$lng = $this->fun->accept('lng', 'R');
		$lng = ($lng == 'big5') ? $this->CON['is_lancode'] : $lng;
		$mid = $this->fun->accept('mid', 'R');
		$sid = $this->fun->accept('sid', 'R');
		if (empty($lng) || empty($mid)) {
			exit('false');
		}
		$lanpackfile = admin_ROOT . 'datacache/' . $lng . '_pack.php';
		if (!is_file($lanpackfile)) {

			$this->creat_lanpack($lng, true);
		}

		if ($sid == 0) {
			$subarray = $this->get_subjectlist_array($sid, $mid, $lng);
			$sublist = $subarray['list'];
			$num = $subarray['num'];
			$typelist = null;
			if ($num > 0) {
				$numcount = $num - 1;
				foreach ($sublist as $key => $value) {
					if ($key == $numcount) {
						$typelist.=$value['sid'];
					} else {
						$typelist.=$value['sid'] . ',';
					}
				}
			} else {
				$num = 0;
			}
		} else {
			$typelist = $sid;
			$num = 1;
		}

		$var = '{"num":"' . $num . '","typelist":"' . $typelist . '","mid":"' . $mid . '","lng":"' . $lng . '"}';
		exit($var);
	}

	function oncreatedoc() {
		$this->powercheck(205, 208);
		parent::start_template();
		$tab = $this->fun->accept('tab', 'R');
		$tab = empty($tab) ? 'true' : $tab;

		$mid = $this->fun->accept('mid', 'R');
		$mid = empty($mid) ? 0 : $mid;

		$lng = $this->fun->accept('lng', 'R');
		$lng = empty($lng) ? ($this->CON['is_alonelng'] && !empty($this->CON['home_lng'])) ? $this->CON['home_lng'] : $this->CON['default_lng'] : $lng;

		$lnglist = $this->get_lng_array($lng, 1);
		$this->ectemplates->assign('lnglist', $lnglist['list']);

		$modelarray = $this->get_model(0, $lng, 1, 1);
		$this->ectemplates->assign('modelarray', $modelarray['list']);
		$is_html = $this->CON['is_html'];
		$this->ectemplates->assign('is_html', $is_html);
		$this->ectemplates->assign('tab', $tab);
		$this->ectemplates->assign('is_alonelng', $this->CON['is_alonelng']);
		$this->ectemplates->assign('home_lng', $lng);
		$this->ectemplates->display('creat/creat_doc');
	}

	function oncreatedocwindow() {
		$this->powercheck(205, 208);
		parent::start_template();
		$read['lng'] = $this->fun->accept('lng', 'R');
		$read['mid'] = $this->fun->accept('mid', 'R');
		$read['tid'] = $this->fun->accept('tid', 'R');
		$read['startid'] = $this->fun->accept('startid', 'R');
		$read['endid'] = $this->fun->accept('endid', 'R');
		$read['time'] = time();
		$is_html = $this->CON['is_html'];
		$this->ectemplates->assign('is_html', $is_html);
		$this->ectemplates->assign('read', $read);
		$this->ectemplates->display('creat/create_doc_window');
	}

	function onindexsave() {
		$this->powercheck(205, 206);
		$this->start_pagetemplate();

		$http_pathtype = $this->CON['http_pathtype'];

		$file_fileex = $this->CON['file_fileex'];

		$entrance_file = $this->CON['entrance_file'];
		$entrance_file = empty($entrance_file) ? 'index' : $entrance_file;

		$file_htmldir = $this->CON['file_htmldir'];
		$htmdirpath = admin_ROOT . $file_htmldir;

		$lng = $this->fun->accept('lng', 'P');
		$lng_templates = $lng;
		$lng = ($lng == 'big5') ? $this->CON['is_lancode'] : $lng;
		if (empty($lng)) {
			exit('{"type":"false","err":"w"}');
		}
		include_once admin_ROOT . 'datacache/' . $lng . '_pack.php';

		$lngurl = $this->get_lan_view($lng, 'url');
		$this->pagetemplate->assign('lng', $lng_templates);
		$this->pagetemplate->assign('lngpack', $LANPACK);
		$homelink = $this->get_link('home', '', $lng_templates);
		$this->pagetemplate->assign('homelink', $homelink);
		$this->pagetemplate->assign('mlink', $this->memberlink(array(), $lng_templates));

		$templatesDIR = $this->get_templatesdir('index');

		$templatefilename = $lng . '/' . $templatesDIR . 'index';

		$tpl_file = $this->pagetemplate->tpl_dir . $this->pagetemplate->templatesDIR . $templatefilename . $this->pagetemplate->templatesfileex;

		if ($this->CON['is_alonelng']) {
			$pathurl = empty($lngurl) ? admin_URL . $file_htmldir : $lngurl . '/';
		} else {
			$pathurl = empty($lngurl) ? admin_URL . $file_htmldir . $lng_templates . '/' : $lngurl . '/';
		}
		$this->pagetemplate->assign('pathurl', $pathurl);
		$this->pagetemplate->assign('path', 'index');

		if ($this->CON['is_alonelng']) {
			$dirpath = $htmdirpath;
			$rt_dirpath = $file_htmldir;

			$filename = $dirpath . $entrance_file . '.' . $file_fileex;

			$rt_dirpath_filename = $rt_dirpath . $entrance_file . '.' . $file_fileex;
		} else {
			$dirpath = $htmdirpath . $lng_templates;
			$rt_dirpath = $file_htmldir . $lng_templates;

			if ($this->fun->filemode($htmdirpath)) {

				if (!is_dir($dirpath)) {
					if (!@mkdir($dirpath, 0777, true)) {

						exit('{"type":"false","err":"c"}');
					}
				}
			} else {

				exit('{"type":"false","err":"w"}');
			}

			$filename = $dirpath . '/' . $entrance_file . '.' . $file_fileex;

			$rt_dirpath_filename = $rt_dirpath . '/' . $entrance_file . '.' . $file_fileex;
		}
		if (file_exists($tpl_file)) {
			$this->pagetemplate->assign('rt_filepath', $rt_dirpath_filename);
			$this->pagetemplate->display($templatefilename, $dirname . '_index', true, $filename, $lng_templates);
			$outkey = '{"dir":"' . $rt_dirpath_filename . '","type":"true","err":"n"}';
		} else {
			$outkey = '{"dir":"' . $rt_dirpath_filename . '","type":"false","err":"t"}';
		}
		unset($typeread);
		unset($modelview);
		unset($LANPACK);
		exit($outkey);
	}

	function oncreattypesave() {
		$this->powercheck(205, 207);
		include_once admin_ROOT . 'public/class_htmlpage.php';
		$this->start_pagetemplate();

		$pnumber = $this->fun->accept('pnumber', 'P');

		$http_pathtype = $this->CON['http_pathtype'];

		$file_fileex = $this->CON['file_fileex'];

		$entrance_file = $this->CON['entrance_file'];
		$entrance_file = empty($entrance_file) ? 'index' : $entrance_file;

		$file_htmldir = $this->CON['file_htmldir'];
		$htmdirpath = admin_ROOT . $file_htmldir;

		$lng = $this->fun->accept('lng', 'P');
		$lng_templates = $lng;
		$lng = ($lng == 'big5') ? $this->CON['is_lancode'] : $lng;
		if (empty($lng)) {
			exit('false');
		}
		include admin_ROOT . 'datacache/' . $lng . '_pack.php';

		$lngurl = $this->get_lan_view($lng, 'url');
		$this->pagetemplate->assign('lng', $lng_templates);
		$homelink = $this->get_link('home', '', $lng_templates);
		$this->pagetemplate->assign('homelink', $homelink);

		$mid = $this->fun->accept('mid', 'P');
		$modelview = $this->get_modelview($mid);

		$modelname = $modelview['modelname'];

		$pagemax = $modelview['pagemax'];
		$pagemax = empty($pagemax) ? 20 : $pagemax;

		$pagesylte = $modelview['pagesylte'];

		$isorder = $modelview['isorder'];

		$istime = $modelview['istime'];

		$tid = $this->fun->accept('tid', 'P');
		$typeread = $this->get_type($tid);

		$template = $typeread['template'];
		$readtemplate = $typeread['readtemplate'];

		$styleid = $typeread['styleid'];

		$filenamestyle = $typeread['filenamestyle'];

		$readnamestyle = $typeread['readnamestyle'];

		$typeurl = $typeread['typeurl'];

		$purview = $typeread['purview'];

		$dirname = $typeread['dirname'];

		if ($this->CON['is_alonelng']) {
			$dirpath = $typeread['dirpath'];
			$pathurl = empty($typeurl) ? empty($lngurl) ? admin_URL . $file_htmldir : $lngurl . '/' : $typeurl;
		} else {
			$dirpath = $lng_templates . '/' . $typeread['dirpath'];

			$pathurl = empty($typeurl) ? empty($lngurl) ? admin_URL . $file_htmldir . $lng_templates . '/' : $lngurl . '/' : $typeurl;
		}
		$typeread['rsslink'] = $this->get_link('typerss', $typeread, $lng_templates);
		$this->pagetemplate->assign('type', $typeread);
		$this->pagetemplate->assign('pathurl', $pathurl);

		$current = !$typeread['upid'] ? $typeread['tid'] : $typeread['topid'];
		$this->pagetemplate->assign('path', 'article');
		$this->pagetemplate->assign('current', $current);

		if ($styleid != 4) {
			if (!empty($typeread['keywords'])) {
				$LANPACK['keyword'] = $typeread['keywords'];
			}
			if (!empty($typeread['description'])) {
				$LANPACK['description'] = $typeread['description'];
			}
			$this->pagetemplate->assign('lngpack', $LANPACK);
		}

		$templatesDIR = $this->get_templatesdir('article');

		$templatefilename = $lng . '/' . $templatesDIR . '/' . $template;
		$readtemplatefilename = $lng . '/' . $templatesDIR . '/' . $readtemplate;

		$tpl_file = $this->pagetemplate->tpl_dir . $this->pagetemplate->templatesDIR . $templatefilename . $this->pagetemplate->templatesfileex;

		$tpl_readfile = $this->pagetemplate->tpl_dir . $this->pagetemplate->templatesDIR . $readtemplatefilename . $this->pagetemplate->templatesfileex;

		$rt_dirpath = $file_htmldir . $dirpath;

		$dirpath = $htmdirpath . $dirpath;

		if ($this->fun->filemode($htmdirpath)) {

			if (!is_dir($dirpath)) {
				if (!@mkdir($dirpath, 0777, true)) {
					$outkey = '{"typename":"' . $typeread['typename'] . '","type":"false","err":"c"}';
					exit($outkey);
				}
			}
		} else {
			$outkey = '{"typename":"' . $typeread['typename'] . '","type":"false","err":"w"}';
			exit($outkey);
		}
		if ($styleid == 1) {

			$filename = $dirpath . '/' . $entrance_file . '.' . $file_fileex;

			$rt_dirpath_filename = $rt_dirpath . '/' . $entrance_file . '.' . $file_fileex;
			if (file_exists($tpl_file)) {
				$this->pagetemplate->assign('rt_filepath', $rt_dirpath_filename);
				$this->pagetemplate->display($templatefilename, $dirname . '_index', true, $filename, $lng_templates);
				$outkey = '{"typename":"' . $typeread['typename'] . '","dir":"' . $rt_dirpath_filename . '","type":"true","err":"n"}';
			} else {
				$outkey = '{"typename":"' . $typeread['typename'] . '","dir":"' . $rt_dirpath_filename . '","type":"false","err":"t"}';
			}
			unset($typeread);
			unset($modelview);
			unset($LANPACK);
			exit($outkey);
		} elseif ($styleid == 2) {

			$db_table = db_prefix . 'document';
			if ($typeread['ispart']) {
				$db_where = ' WHERE lng=\'' . $lng . '\' AND isclass=1 AND mid=' . $mid . ' AND ' . $this->get_typeid($tid, 'tid', 0, $mid, 0, $lng) . " OR FIND_IN_SET('$tid',extid)";
			} else {
				$db_where = ' WHERE lng=\'' . $lng . '\' AND isclass=1 AND mid=' . $mid . ' AND tid=' . $tid . " OR FIND_IN_SET('$tid',extid)";
			}
			$countnum = $this->db_numrows($db_table, $db_where);
			if ($countnum > 0) {

				$numpage = ceil($countnum / $pagemax);

				if (!empty($pnumber)) {
					$numpage = $numpage > $pnumber ? $pnumber : $numpage;
				}
			} else {
				$numpage = 1;
			}

			$rt_dirpath_filename = $rt_dirpath;
			if (file_exists($tpl_file)) {
				for ($index = 1; $index <= $numpage; $index++) {

					$fileArray = array('dirname' => $dirname, 'tid' => $tid, 'datetime' => date("YmdHis"), 'pageid' => $index);

					$filename_str = $this->get_htmlfilename($filenamestyle, $fileArray, 'pageid');
					$array = array();
					$db_table = db_prefix . 'document';
					$sql = "SELECT did,lng,pid,mid,aid,tid,extid,sid,fgid,linkdid,isclass,islink,ishtml,ismess,isorder,purview,recommend,tsn,title,longtitle,
					color,author,source,pic,link,oprice,bprice,click,addtime,template,keywords,description,filename,filepath FROM $db_table $db_where LIMIT 0,$pagemax";
					$this->htmlpage = new htmlpage($sql, $pagemax, $index, $countnum, $numpage, $pagesylte, $entrance_file, $file_fileex, 5, $LANPACK['pagebotton'], $LANPACK['gopageurl'], $filename_str);
					$sql = $this->htmlpage->PageSQL('pid,did', 'down');
					$rs = $this->db->query($sql);
					while ($rsList = $this->db->fetch_assoc($rs)) {
						$attarray = array();
						$rsList['value'] = $this->get_document_value($rsList['did'], 'value');
						if (!empty($rsList['value'])) {
							$attarray = unserialize($rsList['value']);
							unset($rsList['value']);
						}
						$typeread = $this->get_type($rsList['tid']);
						$rsList['typename'] = $typeread['typename'];
						$rsList['typelink'] = $this->get_link('type', $typeread, $lng_templates);
						$rsList['link'] = $this->get_link('doc', $rsList, $lng_templates);
						$rsList['buylink'] = $this->get_link('buylink', $rsList, $lng_templates);
						$rsList['enqlink'] = $this->get_link('enqlink', $rsList, $lng_templates);
						$rsList['ctitle'] = empty($rsList['color']) ? $rsList['title'] : "<font color='" . $rsList['color'] . "'>" . $rsList['title'] . "</font>";
						$array[] = is_array($attarray) ? array_merge_recursive($rsList, $attarray) : $rsList;
					}
					$this->pagetemplate->assign('pagetext', $this->htmlpage->PageStat($LANPACK['pagetext']));
					$this->pagetemplate->assign('pagebotton', $this->htmlpage->PageList());
					$this->pagetemplate->assign('pagenu', $this->htmlpage->Bottonstyle(false));
					$this->pagetemplate->assign('pagese', $this->htmlpage->pageSelect());
					$this->pagetemplate->assign('pagevt', $this->htmlpage->Prevbotton());
					$this->pagetemplate->assign('array', $array);

					$filename_out = $index == 1 ? $entrance_file : $this->get_htmlfilename($filenamestyle, $fileArray);
					$filename = $dirpath . '/' . $filename_out . '.' . $file_fileex;
					$this->pagetemplate->assign('rt_filepath', $rt_dirpath_filename);
					$this->pagetemplate->display($templatefilename, $dirname . '_list', true, $filename, $lng_templates);
					unset($array);
				}
				$outkey = '{"typename":"' . $typeread['typename'] . '","dir":"' . $rt_dirpath_filename . '","type":"true","err":"n"}';
			} else {
				$outkey = '{"typename":"' . $typeread['typename'] . '","dir":"' . $rt_dirpath_filename . '","type":"false","err":"t"}';
			}
			unset($typeread);
			unset($modelview);
			unset($LANPACK);
			exit($outkey);
		} elseif ($styleid == 3) {

		} elseif ($styleid == 4) {
			$db_table = db_prefix . 'document';
			if ($typeread['ispart']) {
				$db_sql = "SELECT did FROM $db_table WHERE isclass=1 AND mid=$mid AND tid=$tid OR FIND_IN_SET('$tid',extid) ORDER BY pid,did DESC LIMIT 0,1";
			} else {
				$db_sql = "SELECT did FROM $db_table WHERE isclass=1 AND mid=$mid AND tid=$tid ORDER BY pid,did DESC LIMIT 0,1";
			}
			$readdid = $this->db->fetch_first($db_sql);
			if ($readdid) {
				$readinfo = $this->get_document($readdid['did']);
				$readinfo['content'] = html_entity_decode($readinfo['content']);
				$readinfo['buylink'] = $this->get_link('buylink', $readinfo, $lng_templates);
				$readinfo['enqlink'] = $this->get_link('enqlink', $readinfo, $lng_templates);

				if (!empty($readinfo['keywords'])) {
					$LANPACK['keyword'] = $readinfo['keywords'];
				}
				if (!empty($readinfo['description'])) {
					$LANPACK['description'] = $readinfo['description'];
				}
				$this->pagetemplate->assign('lngpack', $LANPACK);

				if (!empty($readinfo['linkdid'])) {
					$readinfo['linkdid'] = str_replace(',', '/', $readinfo['linkdid']);
				}
				$albumarray = $this->get_album_array($readinfo['did']);

				$docarray = array();
				if (!empty($readinfo['value'])) {
					$attarray = unserialize($readinfo['value']);
					unset($readinfo['value']);
					$docarray = is_array($attarray) ? array_merge_recursive($readinfo, $attarray) : $readinfo;
				} else {
					$docarray = $readinfo;
				}
				unset($readinfo);
				$this->pagetemplate->assign('read', $docarray);
				$this->pagetemplate->assign('photo', $albumarray);
			}
			$rt_dirpath_filename = $rt_dirpath;
			if (file_exists($tpl_file)) {
				$filename = $dirpath . '/' . $entrance_file . '.' . $file_fileex;
				$this->pagetemplate->assign('rt_filepath', $rt_dirpath_filename);
				$this->pagetemplate->display($readtemplatefilename, $dirname . '_list', true, $filename, $lng_templates);
				$outkey = '{"typename":"' . $typeread['typename'] . '","dir":"' . $rt_dirpath_filename . '","type":"true","err":"n"}';
			} else {
				$outkey = '{"typename":"' . $typeread['typename'] . '","dir":"' . $rt_dirpath_filename . '","type":"false","err":"t"}';
			}
			unset($docarray);
			unset($typeread);
			unset($modelview);
			unset($LANPACK);
			exit($outkey);
		}
	}

	function oncreatdocsave() {
		$this->powercheck(205, 208);
		$lng = $this->fun->accept('lng', 'P');
		$db_where = ' WHERE isclass=1 AND islink=0 AND ishtml=1';
		$mid = $this->fun->accept('mid', 'P');
		if (!empty($mid)) {
			$db_where.=' AND mid=' . $mid;
		}
		$tid = $this->fun->accept('tid', 'P');
		if (!empty($tid)) {
			$db_where.=" AND tid=$tid";
		}
		$startid = $this->fun->accept('startid', 'P');
		$endid = $this->fun->accept('endid', 'P');
		if (!empty($startid)) {
			$db_where.=" AND did BETWEEN $startid and $endid";
		}
		$creattype = $this->fun->accept('creattype', 'P');
		$time = $this->fun->accept('dtime', 'P');
		if ($creattype == 1) {
			$time = $this->fun->formatdate($time, 4);
			$db_where.=" AND addtime>=$time";
		}
		$typeread = $this->get_type($tid);
		if ($this->CON['is_alonelng']) {
			$rt_dirpath_filename = $typeread['dirpath'];
		} else {
			$rt_dirpath_filename = $lng . '/' . $typeread['dirpath'];
		}
		$db_table = db_prefix . 'document';
		$sql = 'SELECT did FROM ' . $db_table . $db_where;
		$rs = $this->db->query($sql);
		while ($rsList = $this->db->fetch_assoc($rs)) {
			$this->articlehtml($rsList['did'], $lng);
		}
		$outkey = '{"typename":"' . $typeread['typename'] . '","dir":"' . $rt_dirpath_filename . '","type":"true","err":"n"}';
		unset($rsList);
		exit($outkey);
	}

	function oncreatsubjectsave() {
		$this->powercheck(205, 210);
		include_once admin_ROOT . 'public/class_htmlpage.php';
		$this->start_pagetemplate();

		$http_pathtype = $this->CON['http_pathtype'];

		$file_fileex = $this->CON['file_fileex'];

		$entrance_file = $this->CON['entrance_file'];
		$entrance_file = empty($entrance_file) ? 'index' : $entrance_file;

		$file_htmldir = $this->CON['file_htmldir'];
		$htmdirpath = admin_ROOT . $file_htmldir;

		$lng = $this->fun->accept('lng', 'P');
		$lng_templates = $lng;
		$lng = ($lng == 'big5') ? $this->CON['is_lancode'] : $lng;
		if (empty($lng)) {
			exit('false');
		}
		include admin_ROOT . 'datacache/' . $lng . '_pack.php';

		$lngurl = $this->get_lan_view($lng, 'url');
		$this->pagetemplate->assign('lng', $lng_templates);
		$homelink = $this->get_link('home', '', $lng_templates);
		$this->pagetemplate->assign('homelink', $homelink);

		$mid = $this->fun->accept('mid', 'P');
		$modelview = $this->get_modelview($mid);

		$modelname = $modelview['modelname'];

		$pagemax = $modelview['pagemax'];
		$pagemax = empty($pagemax) ? 20 : $pagemax;

		$pagesylte = $modelview['pagesylte'];

		$sid = $this->fun->accept('sid', 'P');
		$subread = $this->get_subjectlist_purview($sid);

		$template = $subread['template'];

		$styleid = $subread['styleid'];

		$filenamestyle = $subread['filenamestyle'];

		$readnamestyle = $subread['readnamestyle'];

		$purview = $subread['purview'];

		$dirname = $subread['dirname'];

		if ($this->CON['is_alonelng']) {
			$dirpath = $subread['dirpath'];
			$pathurl = empty($lngurl) ? admin_URL . $file_htmldir : $lngurl . '/';
		} else {
			$dirpath = $lng_templates . '/' . $subread['dirpath'];

			$pathurl = empty($lngurl) ? admin_URL . $file_htmldir . $lng_templates . '/' : $lngurl . '/';
		}
		$this->pagetemplate->assign('sub', $subread);
		$this->pagetemplate->assign('pathurl', $pathurl);

		if (!empty($subread['keywords'])) {
			$LANPACK['keyword'] = $subread['keywords'];
		}
		if (!empty($subread['description'])) {
			$LANPACK['description'] = $subread['description'];
		}
		$this->pagetemplate->assign('lngpack', $LANPACK);
		$this->pagetemplate->assign('path', 'sub');

		$templatesDIR = $this->get_templatesdir('article');

		$templatefilename = $lng . '/' . $templatesDIR . '/' . $template;

		$tpl_file = $this->pagetemplate->tpl_dir . $this->pagetemplate->templatesDIR . $templatefilename . $this->pagetemplate->templatesfileex;

		$rt_dirpath = $file_htmldir . $dirpath;

		$dirpath = $htmdirpath . $dirpath;

		if ($this->fun->filemode($htmdirpath)) {

			if (!is_dir($dirpath)) {
				if (!@mkdir($dirpath, 0777, true)) {
					$outkey = '{"typename":"' . $subread['subjectname'] . '","type":"false","err":"c"}';
					exit($outkey);
				}
			}
		} else {
			$outkey = '{"typename":"' . $subread['subjectname'] . '","type":"false","err":"w"}';
			exit($outkey);
		}

		if ($styleid == 1) {

			$filename = $dirpath . '/' . $entrance_file . '.' . $file_fileex;

			$rt_dirpath_filename = $rt_dirpath . '/' . $entrance_file . '.' . $file_fileex;
			if (file_exists($tpl_file)) {
				$this->pagetemplate->assign('rt_filepath', $rt_dirpath_filename);
				$this->pagetemplate->display($templatefilename, $dirname . '_index', true, $filename, $lng_templates);
				$outkey = '{"typename":"' . $subread['subjectname'] . '","dir":"' . $rt_dirpath_filename . '","type":"true","err":"n"}';
			} else {
				$outkey = '{"typename":"' . $subread['subjectname'] . '","dir":"' . $rt_dirpath_filename . '","type":"false","err":"t"}';
			}
			unset($subread);
			unset($modelview);
			unset($LANPACK);
			exit($outkey);
		} elseif ($styleid == 2) {

			$db_table = db_prefix . 'document';
			$db_where = ' WHERE lng=\'' . $lng . '\' AND isclass=1 AND mid=' . $mid . ' AND sid=' . $sid;
			$countnum = $this->db_numrows($db_table, $db_where);
			if ($countnum > 0) {

				$numpage = ceil($countnum / $pagemax);
			} else {
				$numpage = 1;
			}

			$rt_dirpath_filename = $rt_dirpath;
			if (file_exists($tpl_file)) {
				for ($index = 1; $index <= $numpage; $index++) {

					$fileArray = array('dirname' => $dirname, 'sid' => $sid, 'datetime' => date("YmdHis"), 'pageid' => $index);

					$filename_str = $this->get_htmlfilename($filenamestyle, $fileArray, 'pageid');
					$array = array();

					$db_table = db_prefix . 'document';
					$db_where = ' WHERE lng=\'' . $lng . '\' AND isclass=1 AND mid=' . $mid . ' AND sid=' . $sid;
					$sql = "SELECT did,lng,pid,mid,aid,tid,sid,fgid,linkdid,isclass,islink,ishtml,ismess,isorder,purview,recommend,tsn,title,longtitle,
					color,author,source,pic,link,oprice,bprice,click,addtime,template,keywords,description,filename,filepath FROM $db_table $db_where LIMIT 0,$pagemax";
					$this->htmlpage = new htmlpage($sql, $pagemax, $index, $countnum, $numpage, $pagesylte, $entrance_file, $file_fileex, 5, $LANPACK['pagebotton'], $LANPACK['gopageurl'], $filename_str);
					$sql = $this->htmlpage->PageSQL('pid,did', 'down');
					$rs = $this->db->query($sql);
					while ($rsList = $this->db->fetch_assoc($rs)) {
						$attarray = array();
						$rsList['value'] = $this->get_document_value($rsList['did'], 'value');
						if (!empty($rsList['value'])) {
							$attarray = unserialize($rsList['value']);
							unset($rsList['value']);
						}
						$rsList['link'] = $this->get_link('doc', $rsList, $lng_templates);
						$rsList['buylink'] = $this->get_link('buylink', $rsList, $lng_templates);
						$rsList['enqlink'] = $this->get_link('enqlink', $readinfo, $lng_templates);
						$rsList['ctitle'] = empty($rsList['color']) ? $rsList['title'] : "<font color='" . $rsList['color'] . "'>" . $rsList['title'] . "</font>";
						$array[] = is_array($attarray) ? array_merge_recursive($rsList, $attarray) : $rsList;
					}
					$this->pagetemplate->assign('pagetext', $this->htmlpage->PageStat($LANPACK['pagetext']));
					$this->pagetemplate->assign('pagebotton', $this->htmlpage->PageList());
					$this->pagetemplate->assign('pagenu', $this->htmlpage->Bottonstyle(false));
					$this->pagetemplate->assign('pagese', $this->htmlpage->pageSelect());
					$this->pagetemplate->assign('pagevt', $this->htmlpage->Prevbotton());


					$this->pagetemplate->assign('array', $array);

					$filename_out = $index == 1 ? $entrance_file : $this->get_htmlfilename($filenamestyle, $fileArray);
					$filename = $dirpath . '/' . $filename_out . '.' . $file_fileex;
					$this->pagetemplate->assign('rt_filepath', $rt_dirpath_filename);
					$this->pagetemplate->display($templatefilename, $dirname . '_list', true, $filename, $lng_templates);
					unset($array);
				}
				$outkey = '{"typename":"' . $subread['subjectname'] . '","dir":"' . $rt_dirpath_filename . '","type":"true","err":"n"}';
			} else {
				$outkey = '{"typename":"' . $subread['subjectname'] . '","dir":"' . $rt_dirpath_filename . '","type":"false","err":"t"}';
			}
			unset($subread);
			unset($modelview);
			unset($LANPACK);
			exit($outkey);
		} elseif ($styleid == 3) {

		}
	}

}
?>
